package org.mark.sell.controller;


import org.mark.common.response.Result;
import org.mark.sell.entity.RouteInfo;
import org.mark.sell.service.RouteInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 路线规划信息
 */
@RestController
@RequestMapping("/routeInfo")
@CrossOrigin
public class RouteInfoController {

    @Autowired
    RouteInfoService routeInfoService;

    @RequestMapping("/selectSiteInfoList")
    public Result selectSiteInfoList( @RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize,
                                      @RequestParam(required = false) String name){
        Result page = routeInfoService.page(pageNum, pageSize, name);
        return page;
    }

    @RequestMapping("/selectRouteInfoList")
    public Result selectRouteInfoList(@RequestBody RouteInfo routeInfo) {
        List<RouteInfo> list = routeInfoService.selectRouteInfoList(routeInfo);
        return Result.success(list);
    }

    @RequestMapping("/selectRouteInfoById")
    public Result selectRouteInfoById(Integer id) {
        return Result.success(routeInfoService.selectRouteInfoById(id));
    }

    @RequestMapping("/insertRouteInfo")
    public Result insertRouteInfo(@RequestBody RouteInfo routeInfo) {
        int id = routeInfoService.insertRouteInfo(routeInfo);
        if(id > 0){
            return Result.success("操作成功",id);
        }else {
            return Result.fail("操作失败");
        }
    }

    @RequestMapping("/updateRouteInfoById")
    public Result updateRouteInfoById(@RequestBody RouteInfo routeInfo) {
        if(routeInfoService.updateRouteInfoById(routeInfo) > 0){
            return Result.success("操作成功");
        }else {
            return Result.fail("操作失败");
        }
    }

    @RequestMapping("/deleteRouteInfoById")
    public Result deleteRouteInfoById(@RequestBody RouteInfo routeInfo) {
        return Result.success(routeInfoService.deleteRouteInfoById(routeInfo.getId()));
    }



}